package com.zdw.demo;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
import com.alicp.jetcache.anno.config.EnableMethodCache;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

//@Import(DataSourceConfig.class) //DataSourceConfig是上面配置文件的
@SpringBootApplication(
    scanBasePackages = {"com.zdw.demo","com.zdw.common.config"},
    //多数据源Dynamic+连接池Druid时,需要排除这个配置
    exclude = DruidDataSourceAutoConfigure.class
)
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrix
@MapperScan(basePackages = "com.zdw.demo.mapper")
// jetcache--启用缓存的主开关(CreateCache等注解)
@EnableCreateCacheAnnotation
// jetcache--开启方法注解
@EnableMethodCache(basePackages = "com.zdw.demo")
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    /**
     * 模拟请求
     */
    @RestController
    class EchoController {
        @GetMapping(value = "/test/{string}")
        public String test(@PathVariable String string) {
            return "Hello Nacos Discovery " + string;
        }
    }

}
